home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
Issue38
/
BuildPro
/
MY PROJECT 1
/
Main.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-04-22
|
4KB
|
169 lines
unit Main;
interface
uses Windows, Classes, Graphics, Forms, Controls, Menus,
Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls;
type
TMainForm = class(TForm)
LogoAppMenu: TMainMenu;
FileMenu: TMenuItem;
FileNewItem: TMenuItem;
FileOpenItem: TMenuItem;
FileSaveItem: TMenuItem;
FileSendItem: TMenuItem;
FileExitItem: TMenuItem;
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
Help1: TMenuItem;
AboutItem: TMenuItem;
SpeedPanel: TPanel;
OpenBtn: TSpeedButton;
SaveBtn: TSpeedButton;
ExitBtn: TSpeedButton;
StatusBar: TStatusBar;
RichEdit1: TRichEdit;
SendBtn: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure FileExit(Sender: TObject);
procedure FileNew(Sender: TObject);
procedure FileOpen(Sender: TObject);
procedure FileSave(Sender: TObject);
procedure FileSaveAs(Sender: TObject);
procedure FileSend(Sender: TObject);
procedure About(Sender: TObject);
procedure ShowHint(Sender: TObject);
private
FFileName: String;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
uses SysUtils, Mapi, AboutMyProduct, Debug;
{$R *.DFM}
resourcestring
rsUntitled = 'Untitled';
rsOverwrite = 'OK to overwrite %s';
rsSendError = 'Error sending mail';
procedure TMainForm.FormCreate(Sender: TObject);
var
ResourceData: TResourceStream;
begin
Application.OnHint := ShowHint;
// Extract default untitled file.
ResourceData := TResourceStream.Create (HInstance, 'DefaultUntitled', RT_RCDATA);
try
ResourceData.SaveToFile (ExtractFilePath (Application.ExeName) + 'Untitled.txt');
finally
ResourceData.Free;
end;
FileNew (Self);
end;
procedure TMainForm.FileNew(Sender: TObject);
begin
FFileName := rsUntitled;
RichEdit1.Lines.LoadFromFile (ExtractFilePath (Application.ExeName) + 'Untitled.txt');
RichEdit1.Modified := False;
end;
procedure TMainForm.FileOpen(Sender: TObject);
begin
if OpenDialog.Execute then
begin
RichEdit1.Lines.LoadFromFile(OpenDialog.FileName);
FFileName := OpenDialog.FileName;
RichEdit1.SetFocus;
RichEdit1.Modified := False;
RichEdit1.ReadOnly := ofReadOnly in OpenDialog.Options;
end;
end;
procedure TMainForm.FileSave(Sender: TObject);
begin
if FFileName = rsUntitled then
FileSaveAs(Sender)
else
begin
RichEdit1.Lines.SaveToFile(FFileName);
RichEdit1.Modified := False;
end;
end;
procedure TMainForm.FileSaveAs(Sender: TObject);
begin
if SaveDialog.Execute then
begin
if FileExists(SaveDialog.FileName) then
if MessageDlg(Format (rsOverwrite, [SaveDialog.FileName]),
mtConfirmation, mbYesNoCancel, 0) <> idYes then Exit;
RichEdit1.Lines.SaveToFile(SaveDialog.FileName);
FFileName := SaveDialog.FileName;
RichEdit1.Modified := False;
end;
end;
procedure TMainForm.FileSend(Sender: TObject);
var
MapiMessage: TMapiMessage;
MError: Cardinal;
MessageText: String;
begin
// This will be compiled out if debug information is turned off.
if DebugOn then begin
RichEdit1.Lines.Add ('Message created on ' + FormatDateTime ('hh:mm:ss ddd mmm yyyy', Now));
end;
MessageText := RichEdit1.Lines.Text;
with MapiMessage do begin
ulReserved := 0;
lpszSubject := nil;
lpszNoteText := PChar(MessageText);
lpszMessageType := nil;
lpszDateReceived := nil;
lpszConversationID := nil;
flFlags := 0;
lpOriginator := nil;
nRecipCount := 0;
lpRecips := nil;
nFileCount := 0;
lpFiles := nil;
end;
MError := MapiSendMail(0, 0, MapiMessage,
MAPI_DIALOG or MAPI_LOGON_UI or MAPI_NEW_SESSION, 0);
if MError <> 0 then MessageDlg(rsSendError, mtError, [mbOK], 0);
end;
procedure TMainForm.FileExit(Sender: TObject);
var
X: Integer;
begin
Close;
end;
procedure TMainForm.About(Sender: TObject);
begin
AboutBox.ShowModal;
end;
procedure TMainForm.ShowHint(Sender: TObject);
begin
StatusBar.SimpleText := Application.Hint;
end;
end.